#include<cstdio>
#include<stdlib.h>
#include"GUI.h"
#include"function_1.h"
#include"function_2.h"
#include"function_3.h"
#include"functions.h"
#include<mysql.h>
#include<unistd.h>
extern MYSQL *mysql;
int system_1()
{
	int sc;
	while(1)
	{
		system("clear");
		GUI_2();
		scanf("%d",&sc);
		switch(sc)
		{
			case 1:
				{
					char mysql_insert[100];
					char name[20];
					int ID,age;
					printf("请输入要添加的学生信息：学号、姓名、年龄,以空格为分隔:");
					scanf("%d %s %d", &ID ,name , &age);
					sprintf(mysql_insert,"INSERT INTO tb1 (id,name,age) values('%d','%s','%d')", ID, name, age);
					sys_insert(mysql_insert);
				}
				break;
			case 2:
				{
					printf("请输入删除学生的ID号(输入0返回):");
					char mysql_delete[10]="tb1";	
					sys_delete(mysql_delete);
				}	
				break;
			case 3:
				sys_1_modify();
				break;
			case 4:
				{
					printf("学号         姓名        年龄\n");
					char sc_query[50] = "select * from tb1";
					sys_search(sc_query);
				}		
				break;
			case 5:
				return 1;
		}
	}
}
int system_2()
{

	int sc;
	while(1)
	{
		system("clear");
		GUI_3();
		scanf("%d",&sc);
		switch(sc)
		{
			case 1:
				{
					char mysql_insert[100];
					char name[20];
					int ID, credit;
					printf("请输入要添加的课程信息：课程ID、课程名、课程学分,以空格为分隔:");
					scanf("%d %s %d", &ID ,name , &credit);
					sprintf(mysql_insert,"INSERT INTO class (ID,class_name,credit) values('%d','%s','%d')", ID, name, credit);
					sys_insert(mysql_insert);
				}
				break;
			case 2:
				{
					printf("请输入删除课程的ID号(输入0返回):");
					char mysql_delete[10]="class";	
					sys_delete(mysql_delete);
				}	
				break;
			case 3:
				{
					char mysql_modify[10]="class";
					sys_2_modify(mysql_modify);
				}
				break;
			case 4:
				{
					char sc_query[50] = "select * from class";
					printf("课程号       名称       学分\n");
					sys_search(sc_query);
				}		
				break;
			case 5:
				return 1;
		}
	}
}
int system_3()
{
	int sc;
	while(1)
	{
		system("clear");
		GUI_4();
		scanf("%d",&sc);
		switch(sc)
		{
			case 1:
				{
					sys_3_search();
				}
				break;
			case 2:
				{
					printf("请输入需要删除的学生学号和课程号:");
					char mysql_delete[10]="ch_class";	
					sys_3_delete(mysql_delete);
				}	
				break;
			case 3:
				{
					char mysql_modify[10]="ch_class";
					sys_3_modify(mysql_modify);
				}
				break;
			case 4:
				{
					printf("1、查询学生选课情况 2、查询课程被选情况 3、查询所有选课情况\n");
					int sc;scanf("%d", &sc);
					if(sc == 1)
					{
						int ch_stuid;
						printf("输入学生学号:");scanf("%d", &ch_stuid);
						char sc_query[100];
						sprintf(sc_query, "select * from ch_class where ch_stuid='%d'", ch_stuid);
						printf("学号        课程        成绩\n");
						sys_search(sc_query);
					}	
					else if(sc == 2)
					{
						int ch_course;
						printf("请输入课程号:");scanf("%d", &ch_course);
						char sc_query[100];
						sprintf(sc_query, "select * from tb1 where ID in (select ch_stuid from ch_class where ch_course='%d')", ch_course);
						printf("学号         姓名       年龄\n");
						sys_search(sc_query);
					}
					else if(sc == 3)
					{
						char sc_query[100] = "select * from ch_class";
						printf("学号        课程       成绩\n");
						sys_search(sc_query);
					}
				}		
				break;
			case 5:
				return 1;
		}
	}
}
